package cn.zz.veggie.model.query;

import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.zz.comm.core.types.query.CommQuery;
import cn.zz.comm.mybaits.types.BaseQuery;
import cn.zz.comm.util.StrUtil;
import cn.zz.veggie.model.domain.Shop;

/**
 * @author zhongq
 * @since 2024/7/26
 */
public class ShopQuery extends CommQuery<Integer> implements BaseQuery<Shop> {
	public String likeName;
	public String likeMobile;
	public Integer status;

	public static ShopQuery ofKeyword(String keyword) {
		final ShopQuery query = new ShopQuery();
		query.likeName = StrUtil.blankToNull(keyword);
		query.column = columnBrief;
		return query;
	}

	@Override
	public void injectCondition(LambdaQueryWrapper<Shop> queryWrapper) {
		queryWrapper.eq(Objects.nonNull(id), Shop::getId, id);
		queryWrapper.in(Objects.nonNull(ids), Shop::getId, ids);
		queryWrapper.eq(Objects.nonNull(status), Shop::getStatus, status);
		queryWrapper.like(Objects.nonNull(likeName), Shop::getName, likeName);
		queryWrapper.like(Objects.nonNull(likeMobile), Shop::getMobile, likeMobile);
		queryWrapper.ge(Objects.nonNull(createdAtStart), Shop::getCreatedAt, createdAtStart);
		queryWrapper.lt(Objects.nonNull(createdAtEnd), Shop::getCreatedAt, createdAtEnd);

	}

	@Override
	public void injectColumn(LambdaQueryWrapper<Shop> queryWrapper) {
		switch (column) {
		case columnId -> queryWrapper.select(Shop::getId);
		case columnBrief -> queryWrapper.select(Shop::getId, Shop::getName);
		}
	}

	@Override
	public void injectOrderBy(Page<Shop> page) {
		// default order
		page.addOrder(OrderItem.desc("id"));
	}
	//

}